/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.db;

import java.io.*;
import java.util.Properties;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class DatabaseConfig {
    private String sqlHost;
    private String sqlDB;
    private String sqlUser;
    private String sqlPassword;
    private Properties prop = new Properties();
    private FileInputStream configFile;

    private static DatabaseConfig dbConfig = null;

    public DatabaseConfig() {
        try {
            configFile = new FileInputStream("../database.config");
        } catch (FileNotFoundException ex1) {
            ex1.printStackTrace();
        }
    }

    public void load()
    {
        try {
            prop.load(configFile);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
         sqlHost = prop.getProperty("Host");
         sqlDB = prop.getProperty("DB");
         sqlUser = prop.getProperty("User");
         sqlPassword = prop.getProperty("Password");
         setDetectPlaying(prop.getProperty("DetectPlaying"));
         setDetectTeams(prop.getProperty("DetectTeams"));
    }

    public void store()
    {
        try {
            prop.store(new FileOutputStream("../database.config"), null);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public static synchronized DatabaseConfig getInstance() {
        if (null == dbConfig)
            dbConfig = new DatabaseConfig();

        return dbConfig;
    }


	/**
	 * @return Returns the sqlDB.
	 */
	public String getSqlDB() {
		return sqlDB;
	}

	/**
	 * @param sqlDB The sqlDB to set.
	 */
	public void setSqlDB(String sqlDB) {
		this.sqlDB = sqlDB;
                prop.setProperty("DB", sqlDB);
	}

	/**
	 * @return Returns the sqlHost.
	 */
	public String getSqlHost() {
		return sqlHost;
	}

	/**
	 * @param sqlHost The sqlHost to set.
	 */
	public void setSqlHost(String sqlHost) {
		this.sqlHost = sqlHost;
                prop.setProperty("Host", sqlHost);
	}

	/**
	 * @return Returns the sqlPassword.
	 */
	public String getSqlPassword() {
		return sqlPassword;
	}

	/**
	 * @param sqlPassword The sqlPassword to set.
	 */
	public void setSqlPassword(String sqlPassword) {
		this.sqlPassword = sqlPassword;
                prop.setProperty("Password", sqlPassword);
	}

    public String getSqlUser(){
        return sqlUser;
    }

    public boolean isDetectTeams() {
        return (detectTeams.equalsIgnoreCase("true"));
    }

    public boolean isDetectPlaying() {
        return (detectPlaying.equalsIgnoreCase("true"));
    }

    public void setSqlUser(String sqlUser){
        this.sqlUser = sqlUser;
        prop.setProperty("User", sqlUser);
    }

    public void setDetectTeams(String detectTeams) {
        this.detectTeams= detectTeams;
        prop.setProperty("DetectTeams", detectTeams);
    }

    public void setDetectPlaying(String detectPlaying) {
        this.detectPlaying = detectPlaying;
        prop.setProperty("DetectPlaying", detectPlaying);
    }

    private String detectTeams; // Szene werden nur gespeichert wenn beide Teams geladen werden
    private String detectPlaying; // Szene werden nur gespeichert nachdem es gespielt wird
}
